﻿Imports System.IO
Public Class Form1
    Dim hklm As String = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\"
    Dim hkcu As String = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\"
    Dim hklm64 As String = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run\"
   Dim FileName As String
   Dim FilePath As Object
   Dim RegistryKey As Object
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      AURdBtn.Select()
   End Sub

   Public Sub Createreg()
      FileName = Nametxt.Text
      FilePath = Pathtxt.Text
      RegistryKey = CreateObject("WScript.Shell")
      Try

         If IO.File.Exists(Pathtxt.Text) = False Then
            MessageBox.Show("So such directory!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
         ElseIf IO.File.Exists(Pathtxt.Text) = True Then

            If AURdBtn.Checked = True Then
               RegistryKey.RegWrite(hklm + FileName, My.Resources.start + FilePath + My.Resources.start)
                    MessageBox.Show("Create Successfully!", "Successfully", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                ElseIf AU64RdBtn.Checked = True Then
                    RegistryKey.RegWrite(hklm64 + FileName, My.Resources.start + FilePath + My.Resources.start)
                    MessageBox.Show("Create Successfully!", "Successfully", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                ElseIf CURdBtn.Checked = True Then
                    RegistryKey.RegWrite(hkcu + FileName, My.Resources.start + FilePath + My.Resources.start)
                    MessageBox.Show("Create Successfully!", "Successfully", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If
         End If
      Catch ex As Exception
         MessageBox.Show("An error has occur while trying to create", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
      End Try
   End Sub

   Public Sub Delreg()
      FileName = Nametxt.Text
      FilePath = Pathtxt.Text

      RegistryKey = CreateObject("WScript.Shell")
      Try

         If IO.File.Exists(Pathtxt.Text) = False Then
            MessageBox.Show("So such directory!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
         ElseIf IO.File.Exists(Pathtxt.Text) = True Then

            If AURdBtn.Checked = True Then
               RegistryKey.RegDelete(hklm + FileName)
                    MessageBox.Show("Delete Successfully!", "Successfully", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                ElseIf AU64RdBtn.Checked = True Then
                    RegistryKey.RegDelete(hklm64 + FileName)
                    MessageBox.Show("Delete Successfully!", "Successfully", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                ElseIf CURdBtn.Checked = True Then
                    RegistryKey.RegDelete(hkcu + FileName)
                    MessageBox.Show("Delete Successfully!", "Successfully", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If
         End If
      Catch ex As Exception
         MessageBox.Show("An error has occur while trying to delete", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
      End Try
   End Sub

   Public Sub cchckdir()
      If Pathtxt.Text = Nothing Then
         MessageBox.Show("Please Input Text!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
      ElseIf Nametxt.Text = Nothing Then
         MessageBox.Show("Please Input Text!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

      Else
         Createreg()
      End If
   End Sub

   Public Sub dchckdir()
      If Pathtxt.Text = Nothing Then
         MessageBox.Show("Please Input Text!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
      ElseIf Nametxt.Text = Nothing Then
         MessageBox.Show("Please Input Text!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

      Else
         Delreg()
      End If
   End Sub

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateBTN.Click

      cchckdir()

   End Sub

   Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse.Click
      Dim BrowseD As New OpenFileDialog
      BrowseD.Title = "Open"
      BrowseD.Filter = "EXE File (*.exe)|*.exe|All Files (*.*)|*.*"
      BrowseD.FileName = ""
      BrowseD.Multiselect = False
      BrowseD.ShowDialog()
      Pathtxt.Text = BrowseD.FileName
   End Sub

   Private Sub Pathtxt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Pathtxt.TextChanged

   End Sub

   Private Sub DeleteBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteBTN.Click
      dchckdir()
   End Sub
End Class
